// component/modal/modal.js
var app = getApp();
Component({
  properties: {
    zIndex:{
      type:Number,
      value:999
    },
    height:{
      type:String,
      value:"604rpx"
    },
    autoClose:{
      type:Boolean,
      value: true
    },
    show:{
      type:Boolean,
      value:false
    },
    transparent:{
      type: Boolean,
      value: false
    },
    borderradius:{
      type: String,
      value:''
    }
  },
  data: {
    _showData:false,
    animation:null,
    model: app.globalData.model,
  },
  methods: {
    show(){
      if (this.data._showData) {
        return;
      }
      this._initAnimate();
      var showanimate = this.animation.translateY("0").step()
      this.setData({
        _showData: true
      },()=>{
        setTimeout(()=>{
          this.setData({
            animation: showanimate.export()
          })
        },50);
      })
    },
    _initAnimate(op = {
      duration: 150,
      timingFunction: 'ease-out',
    }){
      if (!this.animation) {
        var animation = wx.createAnimation(op)
        this.animation = animation;
      }
    },
    hide(){
      if (!this.data._showData){
        return;
      }
      this._initAnimate();
      var hideanimate = this.animation.translateY("100%").step()
      this.setData({
        animation: hideanimate.export()
      })
      setTimeout(()=>{
        this.setData({
          _showData: false
        })
      },200);
    },
    isShow(){
      return this.data._showData;
    },
    catchEvent(e){
      if (this.properties.autoClose){
        this.hide();
        this.triggerEvent("catchEvent",true);
      }
      
    },
    catchEventContent(){
      
    }
  }
})
